package org.yonggan.cmcc.config

import com.typesafe.config.ConfigFactory
import org.apache.kafka.common.serialization.StringDeserializer
import org.apache.spark.streaming.Seconds

/**
  * cmcc 的配置常量
  */
object ConfigConstant {

  private val config = ConfigFactory.load()

  val getConfigParams: (String) => (String) = (str) => config.getString(str)


  /*------------------------kafka 参数配置---------------------------------*/
  // kafka 集群
  val KAFKA_SERVERS = getConfigParams("kafka.servers")
  // 消费者GroupId
  val KAFKA_CONSUMER_GROUPID = getConfigParams("kafka.consumer.group.id")
  // kafka主题
  val KAFKA_TOPIC = getConfigParams("kafka.topic").split(",")
  // kafka配置参数
  val KAFKA_PARAMS = Map[String, Object](
    "bootstrap.servers" -> ConfigConstant.KAFKA_SERVERS,
    "key.deserializer" -> classOf[StringDeserializer],
    "group.id" -> ConfigConstant.KAFKA_CONSUMER_GROUPID,
    "value.deserializer" -> classOf[StringDeserializer],
    "auto.offset.reset" -> "earliest",
    "enable.auto.commit" -> (false: java.lang.Boolean)
  )

  /*------------------------SparkStreaming 参数配置---------------------------------*/
  val SPARK_MAXRATE = getConfigParams("spark.streaming.kafka.maxRate")


  var SPARK_DURATION = Seconds(getConfigParams("spark.streaming.duration").toInt)


  /*------------------------province 映射参数---------------------------------*/
  // 省份编码对照
  def pCode2pName ( pcode:String):String = config.getObject("province").unwrapped().get(pcode).asInstanceOf[String]




}
